package com.keller.controller;

import com.github.pagehelper.PageInfo;
import com.keller.domian.Orders;
import com.keller.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/orders")
public class OrderController {
    @Autowired
    private OrdersService ordersService;
    @RequestMapping("/findAll")
    public ModelAndView findAll(@RequestParam(name = "page", required = true, defaultValue = "1")Integer page, @RequestParam(name = "pageSize", required = true, defaultValue = "4")Integer pageSize) throws Exception {
        ModelAndView mv = new ModelAndView();
        List<Orders> ordersList = ordersService.findAll(page, pageSize);
        PageInfo pageInfo = new PageInfo(ordersList);
        System.out.println(ordersList);
        mv.setViewName("orders-list");
        mv.addObject("pageInfo", pageInfo);
        return mv;
    }



    @RequestMapping("/findById")
    public ModelAndView findOrderDetailById(String id) throws Exception {
        Orders orders = ordersService.findOrderById(id);
        ModelAndView mv = new ModelAndView();
        mv.setViewName("orders-show");
        System.out.println(orders);
        mv.addObject("orders",orders);
        return mv;
    }
}
